home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Apple Guide / Engineering / APISample / APISampleCW / Source / UDocMo.h < prev   
Encoding:
Text File  |  1994-05-26  |  6.4 KB  |  225 lines  |  [TEXT/MPS ]

  1. // Copyright ©1994 Apple Computer, Inc.
  2. // Author: John Powers
  3. // Date:   05-Mar-94
  4.  
  5. // UDocMo.h
  6. // Header for document, art, and related classes.
  7.  
  8. #ifndef __UDOCMO__
  9. #define __UDOCMO__                // #endif __UDOCMO__ is at end of this file
  10.  
  11. // Most of the includes are covered in UApp.h
  12.  
  13. #include <Windows.h>
  14. #include <QDOffscreen.h>        // GWorld
  15.  
  16. #ifndef __UAPP__
  17.     #include "UApp.h"
  18. #endif
  19.  
  20. // Constants (also see UAppShared.h).
  21. // ------------------------------------------------------------------------
  22.  
  23. #define    override virtual
  24.  
  25. // Structures
  26. // ------------------------------------------------------------------------
  27.  
  28. typedef struct {
  29.     short    pictId;
  30.     short    locV;
  31.     short    locH;
  32.     short    layer;
  33.     short    isMoveable;
  34.     short    sequenceID;
  35.     char    name[32];
  36. } ArtType, *ArtPtr, **ArtHan;
  37.  
  38. typedef struct {
  39.     short        artCnt;
  40.     ArtType        art[1];
  41. } ArtListType, *ArtListPtr, **ArtListHan;
  42.  
  43. // ========================================================================
  44. // TBitMap
  45. // ------------------------------------------------------------------------
  46. //    The bit map abstract class.
  47.  
  48. class TBitMap 
  49. {
  50.     private:
  51.     protected:
  52.         Rect    fOffRect;            // Off-screen rectangle, normalized.
  53.     public:
  54.         TBitMap(void);                            // constructor
  55.         virtual ~TBitMap(void);                    // destructor
  56.         virtual void CopyOffToOn(void) {;}                    // to override
  57.         virtual void CopyOffToOn(Rect& /*rectToCopy*/) {;}    // to override
  58.         virtual void CopyOnToOff(void) {;}                    // to override
  59.         virtual void CopyOnToOff(Rect& /*rectToCopy*/) {;}    // to override
  60.         virtual void DoneDrawing(void) {;}                    // to override
  61.         virtual OSErr Init(void) {return noErr;}            // to override
  62.         virtual void PrepareForDrawing(void) {;}            // to override
  63. };
  64.  
  65. // ========================================================================
  66. // TBitMapBW-->TBitMap
  67. // ------------------------------------------------------------------------
  68. //    The bit map B&W class.
  69.  
  70. class TBitMapBW : public TBitMap
  71. {
  72.     private:
  73.         GrafPtr        fOffPort;        // Off-screen grafport.
  74.         GrafPtr        fSavedOnPort;
  75.     protected:
  76.     public:
  77.         TBitMapBW(void);                        // constructor
  78.         virtual ~TBitMapBW(void);                // destructor
  79.         virtual void CopyOffToOn(void);
  80.         override void CopyOffToOn(Rect& rectToCopy);
  81.         virtual void CopyOnToOff(void);
  82.         override void CopyOnToOff(Rect& rectToCopy);
  83.         virtual void DoneDrawing(void);
  84.         override OSErr Init(void);
  85.         virtual void PrepareForDrawing(void);
  86. };
  87.  
  88. // ========================================================================
  89. // TBitMapColor-->TBitMap
  90. // ------------------------------------------------------------------------
  91. //    The bit map color class.
  92.  
  93. class TBitMapColor : public TBitMap
  94. {
  95.     private:
  96.         GWorldPtr     fOffGWorld;        // Off-screen world
  97.         CGrafPtr    fSavedOnPort;
  98.         GDHandle    fSavedOnDevice;
  99.     protected:
  100.     public:
  101.         TBitMapColor(void);                        // constructor
  102.         virtual ~TBitMapColor(void);            // destructor
  103.         virtual void CopyOffToOn(void);
  104.         override void CopyOffToOn(Rect& rectToCopy);
  105.         virtual void CopyOnToOff(void);
  106.         override void CopyOnToOff(Rect& rectToCopy);
  107.         virtual void DoneDrawing(void);
  108.         override OSErr Init(void);
  109.         virtual void PrepareForDrawing(void);
  110. };
  111.  
  112. // ------------------------------------------------------------------------
  113. // A new art class.
  114. // The art drawn in the window.
  115. class TArt
  116. {
  117.     enum {
  118.         kBWOffset =        1        // B&W ID = ColorID+kBWOffset
  119.     };
  120.     private:
  121.         ArtType    fArt;
  122.         short    fLastDepth;
  123.         Rect    fDrawRect;        // Rect of art in window.
  124.     protected:
  125.     public:
  126.         virtual void Draw(short depth);
  127.         virtual void Draw(void);
  128.         virtual void GetDrawRect(Rect* theRect);
  129.         virtual short GetLayer(void) {return this->fArt.layer;}
  130.         virtual void GetName(char* theName);
  131.         virtual short GetSequenceID(void) {return this->fArt.sequenceID;}
  132.         virtual void Init(ArtType theArt);
  133.         virtual Boolean IsMoveable(void) {return this->fArt.isMoveable;}
  134.         virtual void SetDrawRect(Rect* theRect);
  135. };
  136.  
  137. // ------------------------------------------------------------------------
  138. // A class for the art window.
  139. // Manages everything inside the window.
  140. class TDocArt : public TDoc
  141. {
  142.     enum {
  143.         kNotCaseSens =    false,
  144.         kNotDiacSens = false
  145.     };
  146.     private:
  147.         short        fArtResId;        // Art resource id.
  148.         short        fArtCnt;        // Number of art objects
  149.         Boolean        fIsCollision;    // True if a collision occurred.
  150.         Boolean        fWantReset;        // True if a reset is wanted.
  151.         Boolean        fWantShuffle;    // True if a shuffle is wanted.
  152.         Boolean        fWantCollision;    // True if collision event wanted.
  153.         AGEvent        fCollisionEvent;// Event to send if a collision occurred.
  154.         Handle        fhArt;            // Handle to art object list.
  155.         TBitMap*    fOffScreen;        // Our off-screen bitmap.
  156.         static pascal void DrawProc(short depth, short deviceFlags,
  157.                                             GDHandle hTargetDevice,
  158.                                             long userData);
  159.         virtual void DragArt(TArt* theArt);
  160.         virtual void DrawOff(TArt* exceptArt);
  161.         virtual Boolean IsCollision(TArt* theArt, Rect* proposedArtRect);
  162.         virtual Boolean IsOutsideWindow(Rect* proposedArtRect);
  163.         virtual Boolean IsSameLayer(TArt* theArt, TArt* theOtherArt);
  164.     protected:
  165.     public:
  166.                 // Constructor and destructor
  167.         TDocArt(short resID);
  168.         virtual ~TDocArt(void);
  169.                 // Overrides
  170.         override void DoContent(EventRecord* pEvent);
  171.         virtual void DoIdle(void);
  172.         override void Draw(void);
  173.                 // New functions
  174.         virtual Boolean GetLocation(Ptr pName, Rect* theRect);
  175.         virtual OSErr Init(short resID);
  176.         virtual void Reset(void);
  177.         virtual void LoadArt(void);
  178.         virtual void SetCollisionEvent(AGEvent theEvent) {this->fCollisionEvent = theEvent;}
  179.         virtual void SetWantCollision(Boolean doWant) {this->fWantCollision=doWant;}
  180.         virtual void SetWantShuffle(Boolean doWant=true) {this->fWantShuffle=doWant;}
  181.         virtual void SetWantReset(Boolean doWant=true) {this->fWantReset=doWant;}
  182.         virtual void Shuffle(void);
  183.         virtual Boolean WantCollision(void) {return this->fWantCollision;}
  184. };
  185.  
  186.  
  187. // ------------------------------------------------------------------------
  188. // A class for display of feedback.
  189. // Manages everything inside the window.
  190. class TDocFB : public TDoc
  191. {
  192.     private:
  193.         enum {                // Content locations
  194.             kLocH = 10,
  195.             kLocCCV = 14,
  196.             kLocCHV = 26,
  197.             kLocEVV = 38,
  198.             kLocMSV = 50,
  199.             kLocCTV = 56
  200.         };
  201.         Point            fLoc[4];
  202.         ControlHandle    fhControl;
  203.     protected:
  204.     public:
  205.                 // Constructor and destructor
  206.         TDocFB(short resID);
  207.         virtual ~TDocFB(void);
  208.                 // Overrides
  209.         override void DoContent(EventRecord* pEvent);
  210.         override void Draw(void);
  211.                 // New functions
  212.         virtual void DrawData(Str255 string, short mode, short whichData);
  213.         virtual OSErr Init(void);
  214. };
  215.  
  216. // Global indexes for feedback items in the TDocFB window.
  217.  
  218. enum {
  219.     dataCC,
  220.     dataCH,
  221.     dataEV,
  222.     dataTP
  223. };
  224.  
  225. #endif __UDOCMO__